#include "HIV.h"


HIV::HIV(void)
{
}


HIV::~HIV(void)
{
	
}

HIV::HIV(Position position)
{
	this->position.setX(position.getX());
	this->position.setY(position.getY());
}

void HIV::move(double directionX, double directionY)
{
	this->position.setX(this->position.getX()+directionX*speed);
	this->position.setY(this->position.getY()+directionY*speed);
}

void HIV::trace(list<Organ> organList,WhiteBloodCell enemy)
{
	Position nextPosition;
	double legnthBTPoint = sqrt(pow(this->position.getX()-enemy.getPostion().getX(),2)+
		pow(this->position.getY()-enemy.getPostion().getY(),2));
	double lengthBTX = cos(legnthBTPoint);
	double lengthBTY = sin(legnthBTPoint);
	double lengthX = speed*lengthBTX/legnthBTPoint;
	double lengthY = speed*lengthBTY/legnthBTPoint;

	if(this->position.getX()>=enemy.getPostion().getX())
		lengthX*=-1;
	
	if(this->position.getY()>=enemy.getPostion().getY())
		lengthY*=-1;
	
	nextPosition.setX(this->position.getX()+lengthX);
	nextPosition.setY(this->position.getY()+lengthY);

	list<Organ>::iterator organListIter = organList.begin();
	for(;organListIter!=organList.end();organListIter++)
	{
		if((*organListIter).isExist(nextPosition) && enemy.isCuring())
		{
			return;
		}
	}
	this->position.setX(nextPosition.getX());
	this->position.setY(nextPosition.getY());

	kill(enemy);
}

void HIV::kill(WhiteBloodCell enemy)
{
	if(sqrt(pow(enemy.getPostion().getX()-this->position.getX(),2)+
		pow(enemy.getPostion().getY()-this->position.getY(),2))<enemy.getRadius())
		enemy.kill();
}